//
//  AppDelegate.swift
//  SwiftDemo
//
//  Created by Chris on 2017/6/11.
//  Copyright © 2017年 chris. All rights reserved.
//

import UIKit
import UserNotifications
import SVProgressHUD
import AFNetworking

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow()
        window?.backgroundColor = UIColor.white
        window?.rootViewController = CJMainViewController()
        window?.makeKeyAndVisible()
        
        AFNetworkActivityIndicatorManager.shared().isEnabled = true
        setupAuthorizationForNotification()
        setupProgressHud()
        
        return true
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        
        UIApplication.shared.applicationIconBadgeNumber = 0
//        (window?.rootViewController as! CJMainViewController).tabBar.items?[0].badgeValue = nil
    }
}

// MARK: - 应用设置
extension AppDelegate {
    
    /// 设置通知权限
    fileprivate func setupAuthorizationForNotification() {
        // 设置用户授权通知
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .alert, .carPlay, .badge]) { (success, error) in
                print("授权" + (success ? "成功!" : "失败"))
            }
        } else {
            // 10.0以下版本
            let settings = UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)
            UIApplication.shared.registerUserNotificationSettings(settings)
        }
    }
    
    /// 设置svprogresshud显示时间
    fileprivate func setupProgressHud() {
        SVProgressHUD.setMinimumDismissTimeInterval(1.5)
        
    }
}
